package com.gaoshi.chapter4;

public class CompoundInterest {
    public static void main(String[] args) {
        final double STARTRATE = 10;
        final int NRATES = 6;
        final int NYEARS = 10;

        double[] interestRate = new double[NRATES];
        for (int i = 0; i < NRATES; i++) {
            interestRate[i] = (STARTRATE + i) / 100.0;
        }

        double[][] banlances = new double[NYEARS][NRATES];
        for (int i = 0; i < banlances[0].length; i++) {
            banlances[0][i] = 10000;
        }

        for (int i = 1; i < banlances.length; i++) {
            for (int j = 0; j < banlances[i].length; j++) {
//                double oldBanlance = banlances[i - 1][j];
//                double interest = oldBanlance * interestRate[j];
//                banlances[i][j] = oldBanlance + interest;
                banlances[i][j] = banlances[i - 1][j] * (1 + interestRate[j]);
            }
        }

        for (int i = 0; i < interestRate.length; i++) {
            System.out.printf("%9.0f%%", interestRate[i] * 100);
        }
        System.out.println();

        for (int i = 0; i < banlances.length; i++) {
            for (int j = 0; j < banlances[i].length; j++) {
                System.out.printf("%10.2f", banlances[i][j]);
            }
            System.out.println();
        }
    }
}
